package cn.rengy.web.framework.wxmp.component;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.Cache.ValueWrapper;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;

import cn.rengy.web.framework.sql.DbService;
@Service
public class WxComponentAppService {
	@Autowired
	private DbService dbService;
	//private static Logger logger = LoggerFactory.getLogger(WxComponentAppService.class);
	@Autowired
	private CacheManager cacheManager;
	
	//@Cacheable(value="wxComponentAppCache",key="#appid")
	public Map<String,Object> getWxComponentApp(String appid){
		/*WxComponentApp app=null;
		Cache cache=cacheManager.getCache("wxComponentAppCache");
		ValueWrapper valueWrapper=cache.get(appid);
		if(valueWrapper==null){
			app=this.dbService.queryForBean("select_get_wx_component_app", WxComponentApp.class, appid);
			if(app!=null){
				cache.put(appid, app);
			}
		}else{
			app=(WxComponentApp)valueWrapper.get();
		}
		return app;*/
		Map<String,Object> app=null;
		Cache cache=cacheManager.getCache("wxComponentAppCache");
		ValueWrapper valueWrapper=cache.get(appid);
		if(valueWrapper==null){
			app=this.dbService.queryForMap("select_get_wx_component_app", appid);
			if(app!=null){
				cache.put(appid, app);
			}
		}else{
			app=(Map<String,Object>)valueWrapper.get();
		}
		return app;
	}
	/**
	 * 查询第三方平台的VerifyTicket
	 * @param component_appid 平台appid
	 * @return
	 * @throws Exception
	 */
	/*public String getVerifyTicket(String component_appid) throws Exception{
		String ticket=null;
		Cache cache=cacheManager.getCache("componentVerifyTicketCache");
		ValueWrapper valueWrapper=cache.get(component_appid);
		if(valueWrapper==null){
			ticket=this.dbService.querySingleColumn("select_get_verify_ticket", String.class, component_appid);
			if(ticket!=null){
				cache.put(component_appid, ticket);
			}
		}else{
			ticket=(String)valueWrapper.get();
		}
		if(ticket==null){
			throw new Exception ("componentVerifyTicket查询失败");
		}
		return ticket;
	}*/
	
}
